ZF.add('dom-insert', function(Z) {

    var D = Z.Dom,
        PARENT_NODE = 'parentNode',
        INSERT_BEFORE = 'insertBefore',
        APPEND_CHILD = 'appendChild',
        NEXT_SIBLING = 'nextSlibing',
        FIRST_CHILD = 'firstChild';

    var Inserters = {

        before : function(context, element) {
			if (element[PARENT_NODE]) {
                element[PARENT_NODE][INSERT_BEFORE](context, element);
            }
		},

		after : function(context, element) {
			if (!element[PARENT_NODE]) {
                return;
            }

			var next = element[NEXT_SIBLING];
			(next) ? element[PARENT_NODE][INSERT_BEFORE](context, next) : element[PARENT_NODE][APPEND_CHILD](context);
		},

		bottom : function(context, element) {
			element[APPEND_CHILD](context);
		},

		top : function(context, element) {
			var first = element[FIRST_CHILD];
			(first) ? element[INSERT_BEFORE](context, first) : element[APPEND_CHILD](context);
		}
    };

    Z.extend(D, {

        inject : function(element, to, where) {
            Inserters[where || 'bottom'](element, to);
		    return this;
        }

    });

    // make more usefull
    Z.each(Inserters, function(inserter, where){

		D['inject' + Z.String.capitalize(where)] = function(context, element) {
			inserter(context, element);
			return this;
		};

	});

}, { requires : ['dom'] });
